package com.gln.bloger.service.impl;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.xml.sax.InputSource;

import com.gln.bloger.exception.BlogerException;
import com.gln.bloger.pojos.SiteConfig;
import com.gln.bloger.service.SiteConfigService;

public class SiteConfigServiceImpl implements SiteConfigService {

	/**
	 * get site config
	 */
	public SiteConfig getSiteConfig() throws BlogerException {
		Digester d = null;
		//create root object
		SiteConfig siteConfig= null;
			try {
			InputSource ruleFile = new InputSource(this.getClass().getResource("/")+"resources/site-config-digester-rule.xml");
			ruleFile.setEncoding("UTF-8");
			d = DigesterLoader.createDigester(ruleFile);
			//parsing
			siteConfig = (SiteConfig) d.parse(this.getClass().getResource("/")+"resources/site-config.xml");
		}
		catch (Exception e) {
		    e.printStackTrace();
		}
		return siteConfig;
	}
	
//	public static void main(String [] args)throws Exception{
//		SiteConfigServiceImpl sc = new SiteConfigServiceImpl();
//		SiteConfig scg = sc.getSiteConfig();
//		System.out.print(scg);
//	}
}
